package com.lemon.jvm.jdk;

import com.lemon.jvm.hotspot.src.share.vm.classfile.BootClassLoader;
import com.lemon.jvm.hotspot.src.share.vm.oops.InstanceKlass;
import com.lemon.jvm.hotspot.src.share.vm.oops.MethodInfo;
import com.lemon.jvm.hotspot.src.share.vm.prims.JavaNativeInterface;

public class Main {

    public static void main(String[] args) {
        startJVM(args);
    }

    public static void startJVM(String[] args) {
        String t = "load.txt";
        String classPath = Main.class.getClassLoader().getResource(t).getPath();
        classPath = classPath.replace(t,"");
        String mainClass = "com.lemon.jvm.example.HelloWorld";
        BootClassLoader bootClassLoader = new BootClassLoader(classPath);
        InstanceKlass mainKlass =  bootClassLoader.loadKlass(mainClass);
        // 找到main方法
        MethodInfo mainMethod = JavaNativeInterface.getMethodID(mainKlass,"main", "([Ljava/lang/String;)V");
        System.out.println(mainMethod.getMethodName());
    }
}
